<script setup lang="ts">
import { onMounted, ref } from 'vue'
import DoctorCard from './DoctorCard.vue'
import { useWindowSize } from '@vueuse/core'
import { homePageDoc } from '@/services/consult'
import type { DoctorList } from '@/types/consult'
// 定义屏幕的宽度
const { width } = useWindowSize()
// 定义设置屏幕宽度的方法 直接操作dom不太好 这里是用 vueUse这个插件
/* function getWidth() {
  width.value = window.innerWidth
  console.log(width.value)
}
// 绑定事件给 resize 事件
onMounted(() => {
  window.addEventListener('resize', getWidth)
})
// 关闭页面后，需要清除事件
onUnmounted(() => {
  window.removeEventListener('resize', getWidth)
}) */
// 获取医生列表
const current = ref(1)
const pageSize = 10
const doctorList = ref<DoctorList>()
async function getList() {
  const res = await homePageDoc({ current: current.value, pageSize: pageSize })
  console.log(res)
  doctorList.value = res.data.rows
}
onMounted(() => {
  getList()
})
</script>
<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <!-- swipe 组件 -->
      <van-swipe :width="(150 / 375) * width" :show-indicators="false" :loop="false">
        <van-swipe-item v-for="item in doctorList" :key="item.id">
          <DoctorCard :item="item"></DoctorCard>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
